Q: What will be the output of the following JavaScript statement? var grand_Total=eval("10*10+5");
Solution: eval() is a function property of the global object. The argument of the eval() function is a string. If the string represents an expression, eval() evaluates the expression. If the argument represents one or more JavaScript statements, eval() evaluates the statements.
Q: Do functions in JavaScript necessarily return a value?
Solution: Functions generally have a return statement and hence usually returns a value. Some functions which does not have a return statement returns value by default during execution.
Q: Will the following JavaScript code work? var tensquared = (function(x) {return x*x;}(10));
Solution: Function name is optional for functions defined as expressions. Function expressions are sometimes defined and immediately invoked.
Q: What will be the output of the following JavaScript code? var string2Num=parseInt("123xyz");
Solution: The parseInt() function parses a string and returns an integer. The function returns the first integer contained in the string or 0 if the string does not begin with an integer.
Q: If you have a function f and an object o, you can define a method named m of o with ________
Solution: A method is nothing more than a JavaScript function that is stored in a property of an object. If you have a function f and an object o, you can define a method named m of o with the following line: o.m = f;
Q: What will be the output of the following JavaScript code? var arr = [7, 5, 9, 1]; var min = Math.min.apply(null, arr); document.writeln(min);
Solution: The function apply() is used to call a function that contains “this” value and the argument contains elements of an array. Unlike call() method, it contains a single array of arguments.
Q: What will be the output of the following JavaScript code? var add=new Function("num1","num2","return num1+num2"); document.writeln(add(2,5));
Solution: add function is defined in the first line of the code using the new property. Add function returns the sum of the two arguments passed to it.
Q: What will be the output of the following JavaScript code? var a=3.7; var b=2; a=ciel(a) document.writeIn(a*b);
Solution: The ciel function in javascript round offs the value passed in its argument to the next higher closest value. Therefore the value of a will be converted to 4 and hence the output will be 8.
Q: What will be the output of the following JavaScript code? var a=2.99; var ans=floor(a)*floor(a) console.log(ans);
Solution: The floor method round offs the value of the decimal number to the lower limit. Therefore floor of a will be 2 which will result in the output of 4.
Q: What will be the output of the following JavaScript code? var a=225; document.writeln(Math.sqrt(a));
Solution: The JavaScript math sqrt() method returns the square root of a number. If the provided number is negative, it returns NaN.
You Have Score    | /10 |